package com.mc.moring.main.adapter;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mc.moring.R;
import com.mc.moring.bean.MyLoanListBean;
import com.mc.moring.main.MyLoanDetailsActivity;
import com.mc.moring.util.StringUtils;
import com.mc.moring.util.TimeUtils;


public class MyLoanAdapter extends BaseQuickAdapter<MyLoanListBean.dataBean, BaseViewHolder> {

    public MyLoanAdapter() {
        super(R.layout.item_my_loan);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyLoanListBean.dataBean item) {
        helper.setText(R.id.tv_customerName, item.getCustomerName());
        helper.setText(R.id.tv_periods, item.getPeriods());
        helper.setText(R.id.tv_applyAmount, "$" + StringUtils.formatNumberWithCommas(item.getApplyAmount()));
        helper.setText(R.id.tv_createTime, TimeUtils.date2FormatDate(item.getCreateTime().substring(0, 10)));
        TextView tv_status = helper.getView(R.id.tv_status);
        String status = item.getPaymentStatus();
        if (status.equals("-1")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_red_bg);
            tv_status.setTextColor(Color.parseColor("#FF3737"));
            tv_status.setText("Rechazado");

        } else if (status.equals("-2")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_red_bg);
            tv_status.setTextColor(Color.parseColor("#FF3737"));
            tv_status.setText("Desembolso fallido repetidamente");
        }
        else if (status.equals("3002")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_red_bg);
            tv_status.setTextColor(Color.parseColor("#FF3737"));
            tv_status.setText("Atrasado");
        }
        else if (status.equals("3003")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_red_bg);
            tv_status.setTextColor(Color.parseColor("#FF3737"));
            tv_status.setText("null");
        }
        else if (status.equals("1001")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_grey_bg);
            tv_status.setTextColor(Color.parseColor("#DADADA"));
            tv_status.setText("Revisando");
        }
        else if (status.equals("0")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_grey_bg);
            tv_status.setTextColor(Color.parseColor("#DADADA"));
            tv_status.setText("Contrato firmando");
        }
        else if (status.equals("1")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_grey_bg);
            tv_status.setTextColor(Color.parseColor("#DADADA"));
            tv_status.setText("Firma fallída");
        }
        else if (status.equals("1004")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_grey_bg);
            tv_status.setTextColor(Color.parseColor("#DADADA"));
            tv_status.setText("Revisión fallida");
        }
        else if (status.equals("4001")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_green_bg);
            tv_status.setTextColor(Color.parseColor("#00C24E"));


        } else if (status.equals("2002")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_green_bg);
            tv_status.setTextColor(Color.parseColor("#00C24E"));
            tv_status.setText("Desembolso exitoso");
        }
        else if (status.equals("1002")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_810_bg);
            tv_status.setTextColor(Color.parseColor("#FF810A"));
            tv_status.setText("Préstamo aprobado");
        }
        else if (status.equals("2001")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_810_bg);
            tv_status.setTextColor(Color.parseColor("#FF810A"));
            tv_status.setText("Desembolso procesando");
        }
        else if (status.equals("2003")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_810_bg);
            tv_status.setTextColor(Color.parseColor("#FF810A"));
            tv_status.setText("Desembolso fallido");
        }
        else if (status.equals("2004")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_810_bg);
            tv_status.setTextColor(Color.parseColor("#FF810A"));
            tv_status.setText("Desembolso procesando");
        } else if (status.equals("3001")) {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_810_bg);
            tv_status.setTextColor(Color.parseColor("#FF810A"));
            tv_status.setText("Reembolso procesando");
        }
        else {
            tv_status.setBackgroundResource(R.drawable.btn_circle_line_grey_bg);
            tv_status.setTextColor(Color.parseColor("#DADADA"));
            tv_status.setText("Revisando");
        }
        helper.getView(R.id.ll).setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putSerializable("_bean", item);
            Intent intent = new Intent();
            intent.setClass(mContext, MyLoanDetailsActivity.class);
            intent.putExtras(bundle);
            mContext.startActivity(intent);
        });
    }

}
